﻿package dungeonCode 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * @author Josh Davis
	 */
	
	public class Tile extends MovieClip 
	{
		public var type:Number, prevX:Number, prevY:Number;
		public var selected:Boolean = false;
		
		public function Tile() 
		{
			super();
		}
		
		public function init(t:Number, xi:Number, yi:Number):void
		{
			addEventListener(MouseEvent.MOUSE_DOWN, selectTile);
			
			//set image based on tile type
			type = t;
			if (type == 0)
				gotoAndStop("hero");
			else if(type == 1)
				gotoAndStop("wallH");
			else if(type == 2)
				gotoAndStop("wallV");
			else if(type == 3)
				gotoAndStop("treasure");
			else if(type == 4)
				gotoAndStop("floor");
			
			x = xi;
			y = yi;
		}
		
		public function selectTile(e:Event):void
		{
			selected = true;
		}
		
		public function getType():int
		{
			return type;
		}
		
		public function prev(px:Number, py:Number):void
		{
			prevX = px;
			prevY = py;
		}
		
		public function revert():void
		{
			x = prevX;
			y = prevY;
		}
		
		public function destroy():void
        {
			if (parent != null)
				parent.removeChild(this);
		}
	}	
}